package xyz.xiangyushui.dao.connectionFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class JDBCConnectionFactory implements DBConnectoryFactory{
	private final String driver = "jdbc:mysql://localhost:3306/desserthouse?useSSL=true";
	private final String user = "root";
	private final String password = "19960623";
	private Connection connection;

	static {
		try {
			// 加载MySql的驱动类
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			System.out.println("找不到驱动程序类 ，加载驱动失败！");
			e.printStackTrace();
		}
	}
	
	 /** 
     * 建立数据库连接 
     * @return 数据库连接 
     */  
    public Connection getConnection() {  
        try {  
            connection = DriverManager.getConnection(driver, user,  
                    password);  
        } catch (SQLException e) {  
            System.out.println(e.getMessage());  
        }  
        return connection;  
    }  
}
